package com.syni.mdd.yhd.common.all.controller.protect;

/**
 * @className BmsBusinessController
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/15 14:25
 * @VERSION 1.0
 **/

import com.syni.mdd.sjb.common.component.utils.common.annotations.CheckParams;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.constants.ResultCode;
import com.syni.mdd.yhd.common.all.service.BmsGroupMessageReportService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/groupMessageReport")
public class BmsGroupMessageReportController {
    @Autowired
    BmsGroupMessageReportService bmsGroupMessageReportService;

    @PostMapping("/reportGroupMessage")
    @CheckParams(checkAuth = true,params = {"group_message_id","report_type"})
    public Map<String,Object> reportGroupMessage(@RequestBody Map<String,Object> paramsMap){
        Integer userId = Integer.parseInt(paramsMap.get("userIdentify").toString());
        Integer groupMessageId = Integer.parseInt(paramsMap.get("group_message_id").toString());
        Integer reportType = Integer.parseInt(paramsMap.get("report_type").toString());
        String reportContent = null;
        if(paramsMap.containsKey("report_content") && !"".equals(paramsMap.get("report_content").toString())){
            reportContent = paramsMap.get("report_content").toString();
            if(reportContent.length() > Constants.MAX_CONTENT_LENG){
                return ResultMapHelper.result(ResultCode.CODE_BUSINESS_REPORT_ERROR_LONG,"举报内容过长");
            }
        }
        return bmsGroupMessageReportService.doGroupMessageReport(userId,groupMessageId,reportType,reportContent);
    }
}
